#ifndef _CACHEMAP_H_
#define _CACHEMAP_H_
#include <QMap>
#include <QString>
#include <QCache>

class Cache: public QObject
{
public:
    Cache(const QString& name, const QString& file, const QString& md5, const QString& cacheFile = "");

    QString file(){return _filePath;}
    QString md5(){return _md5;}
    QString name(){return _name;}
    QString cache(){return _cache;}
    void setMd5(const QString& md5){_md5 = md5;}
private:
    QString _name;
    QString _filePath;
    QString _md5;
    QString _cache;
    bool _binary;
};

class CacheMap: public QCache<QString, Cache>
{
public:
    CacheMap();
    bool isCachedFile(const QString& fileName);
    bool isCachedName(const QString& name);
    void addToCache(const QString& file, const QString& name, bool fromBinary);

    QString getCachedFile(const QString& name);
    QString getCachedName(const QString& fileName);

    QString fileNameForName(const QString& name);
    void updateMd5(const QString& name);
private:
    void loadCache();
    QString md5(const QString& fileName);
    QMap<QString, QString> _fileMap;
};

#endif
